package com.wealth.scsj.b_app.adapter;

import android.view.View;
import android.widget.RelativeLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.wealth.scsj.b_app.R;
import com.wealth.scsj.b_app.bean.SelectUserHasBindBankCardBean;


import java.util.ArrayList;
import java.util.List;

/**
 * 银行卡列表
 */
public class BankCardListAdapter extends BaseQuickAdapter<SelectUserHasBindBankCardBean.DataBean.ListBean ,BaseViewHolder>{

    private List<Boolean> isClicks;//控件是否被点击,默认为false，如果被点击，改变值，控件根据值改变自身颜色
    public int currentPosition;

    public BankCardListAdapter(List data, int posion) {
        super(R.layout.item_back_card,data);
        isClicks = new ArrayList<>();
        for (int i = 0; i < data.size(); i++) {
            isClicks.add(false);
        }
        if(posion != -1){
            isClicks.set(posion,true);
        }
        currentPosition = posion;
    }
    @Override
    protected void convert(final BaseViewHolder helper, SelectUserHasBindBankCardBean.DataBean.ListBean item) {
//        helper.setImageResource(R.id.img,item.getIc());

        helper.setText(R.id.bank_card_name,item.getUserBankCard().getBankName());
//        helper.setText(R.id.bank_card_name,item.getBankName());

        String cardNo = item.getUserBankCard().getCardNo();
        String substring = cardNo.substring(cardNo.length() - 4, cardNo.length());
        helper.setText(R.id.bank_card_tail,"尾号："+substring);
//        helper.setText(R.id.bank_card_tail,"尾号："+item.getBankTail());

        if(helper.getLayoutPosition() == currentPosition){
            helper.setImageResource(R.id.is_selected,R.mipmap.check_select);
//            helper.setChecked(R.id.is_selected,true);
        }else {
            helper.setImageResource(R.id.is_selected,R.mipmap.check_no_select);
//            helper.setChecked(R.id.is_selected,false);
        }

        RelativeLayout viewRl = (RelativeLayout) helper.getView(R.id.item_rl);

        viewRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                 currentPosition = helper.getLayoutPosition();
                 notifyDataSetChanged();
            }
        });
    }
}
